﻿using Common.Models;
using Core.Entities.SM;
using Core.Entities.Stock;
using Infrastructure.Services;
using Infrastructure.Services.SM;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace WebZHX.Controllers.SM
{
    /// <summary>
    /// 出库记录控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class StockOutController : BaseController<StockOut, string>
    {
        private readonly StockOutService _stockOutService;

        public StockOutController(
            BaseService<StockOut, string> service,
            StockOutService stockOutService)
            : base(service)
        {
            _stockOutService = stockOutService;
        }

        /// <summary>
        /// 根据物料编码查询
        /// </summary>
        /// <param name="materCode">物料编码</param>
        /// <returns>出库记录列表</returns>
        [HttpGet("code/{materCode}")]
        public async Task<ActionResult<IEnumerable<StockOut>>> GetByMaterCode(string materCode)
        {
            var result = await _stockOutService.GetByMaterCodeAsync(materCode);
            return Ok(result);
        }

        /// <summary>
        /// 根据物料名称模糊查询
        /// </summary>
        /// <param name="materName">物料名称</param>
        /// <returns>出库记录列表</returns>
        [HttpGet("name/{materName}")]
        public async Task<ActionResult<IEnumerable<StockOut>>> GetByMaterName(string materName)
        {
            var result = await _stockOutService.GetByMaterNameAsync(materName);
            return Ok(result);
        }

        public class StockOutQueryDto
        {
            /// <summary>
            /// 分页数据
            /// </summary>
            public QueryFilter filter { get; set; }
            /// <summary>
            /// 实体数据
            /// </summary>
            public StockOut StockOut { get; set; }
        }

        /// <summary>
        /// 高级分页查询
        /// </summary>
        /// <param name="stockOutQueryDto">查询参数</param>
        /// <returns>分页结果</returns>
        [HttpPost("StockOutPage")]
        public async Task<ActionResult<PagedResult<StockOut>>> AdvancedPagedQuery([FromBody] StockOutQueryDto stockOutQueryDto)
        {
            var result = await _stockOutService.GetByStockOutAsync(stockOutQueryDto.filter, stockOutQueryDto.StockOut);
            return Ok(result);
        }

        // 注意：这里移除了新增、修改、删除的方法，因为前端不需要这些操作
    }
}